import os
import re
import time

from case.app_element import APPageELE
from common.app_info import GlobalVar
from common.u2_base import ATXBase
from utils.PathUtil import BASE_PATH
from random import randint
from adbutils import adb
from utils.time_utils import YMDHMS__

global app_bind_ele


class TestBindMethod(ATXBase):

    def __init__(self, platform, app_tag):
        super().__init__(platform, app_tag)


        global app_bind_ele
        app_bind_ele = APPageELE()

    def judge_app_hot_cloud_start(self, hotStart="false"):
        """
        launch: 启动方式
        判断app 冷热启动
        回到app 首页，再进行用例的执行。因此每个用例执行完之后不关闭app， 只放到后台或显示首页即可
        目前采用热启动，节省了app冷启动的耗时，已经广告的耗时。 支持iOS手机热启动
        """
        if hotStart.lower() == "true":
            self.back_home_page()
        else:
            self.stop_app()

    def back_home_page(self):
        start_back = time.time()
        while time.time() - start_back <= 20:
            # if self.judge_element_exists(app_bind_ele.FAMILY, timeout=1):
            # 原来找首页tab，可能是在根目录任意tab里，现在强制返回到首页tab
            if self.judge_element_exists(app_bind_ele.HOME_PAGE, timeout=1):
                return True
            else:
                self.press_action(keyId=1)
        self.stop_app()

    def just_back(self, seconds=1.0):
        self.press_action(keyId=1)
        self.sleep_op(seconds)

    def volume_down(self):
        self.press_action(keyId=5)

    def home_page(self):
        if self.find_element(app_bind_ele.HOME_PAGE, timeout=60):
            print('在首页了')
        else:
            raise Exception('一分钟，首页还没加载完成，检查网络')

    def in_home_page(self):
        if self.find_element(app_bind_ele.HOME_PAGE, timeout=2):
            print('在首页了')
            time.sleep(1)
        else:
            # print('不在首页，尝试纠正')
            self.back_home_page()

    def lock_push_msg_page(self):
        e = self.find_element(app_bind_ele.LOCK_PUSH_PAGE, timeout=120)
        if not e:
            raise Exception('120秒没收到按门铃推送')

    def ignore(self):
        pass
        # ignore_ele = self.find_element(app_bind_ele.CURRENT_HOME_IGNORE, timeout=3)
        # if ignore_ele is not None:
        #     ignore_ele.click()


    # app进入固件升级页面-摄像机
    def app_to_upgrade(self):
        try:
            while True:
                self.in_home_page()
                # 有设置从设置进入，没设置从云录进
                home_item_setting = self.find_element(app_bind_ele.HOME_ITEM_SETTING, timeout=3)
                if home_item_setting:
                    home_item_setting.click()
                else:
                    cloud_btn = self.find_element(app_bind_ele.HOME_CLOUD_FLOW_BUTTON)
                    if cloud_btn:
                        cloud_btn.click()
                    else:
                        break
                    setting_icon = self.find_element(app_bind_ele.CLOUD_SETTING)
                    if setting_icon:
                        setting_icon.click()
                    else:
                        continue
                time.sleep(1)
                self.swipe_by_screen(direction='up', scale=0.9)
                self.swipe_by_screen(direction='up', scale=0.9)
                self.swipe_by_screen(direction='up', scale=0.9)
                # 点击 固件升级
                u = self.find_element(app_bind_ele.SETTING_DEVICE_UPGRADE)
                if u:
                    u.click()
                    break
                else:
                    continue
        except Exception as e:
            print('app进入固件升级页面?', e)



    # app进入固件升级页面-生态门锁
    def st_lock_app_to_upgrade(self):
        try:
            while True:
                self.in_home_page()
                # 点击设备
                self.click_door_lock_window()
                # 右上角 设置
                self.setting_btn_st()
                time.sleep(1)
                self.swipe_by_screen(direction='up', scale=0.9)
                self.swipe_by_screen(direction='up', scale=0.9)
                self.swipe_by_screen(direction='up', scale=0.9)
                # 点击 固件升级
                u = self.find_element(app_bind_ele.SETTING_DEVICE_UPGRADE)
                if u:
                    u.click()
                    break
                else:
                    continue
        except Exception as e:
            print('app进入固件升级页面?', e)

    def click_upgrade_item(self):
        # 点击 固件升级
        self.find_element_clickable(app_bind_ele.SETTING_DEVICE_UPGRADE)

    def get_now_version(self):
        if self.find_element(app_bind_ele.UPGRADE_NOW, timeout=3):
            return 0  # 旧版，需要升级
        if self.find_element(app_bind_ele.LAST_VERSION, timeout=3):
            return 1  # 最新版本了，无需升级
        if self.find_element(app_bind_ele.UPLOAD_TRY_AGAIN, timeout=3):
            raise Exception('升级失败-"重试"')
        else:
            return -1  # 疑似异常或者正在升级中

    def click_upgrade_now(self):
        self.find_element_clickable(app_bind_ele.UPGRADE_NOW)
        print('点击"马上升级"')

    def last_version(self):
        e = self.find_element(app_bind_ele.LAST_VERSION)
        if not e:
            e2 = self.find_element(app_bind_ele.UPGRADE_NOW)
            if e2:
                raise Exception('疑似升级失败')

    # 门锁进入固件升级页面
    def lock_app_to_upgrade(self):
        try:
            while True:
                self.in_home_page()
                self.click_device_flow_window()
                time.sleep(0.5)
                setting = self.find_element(app_bind_ele.LOCK_SETTING)
                if setting:
                    setting.click()
                else:
                    break
                time.sleep(1)
                self.swipe_by_screen(direction='up', scale=0.9)
                self.swipe_by_screen(direction='up', scale=0.9)
                # 点击 固件升级
                u = self.find_element(app_bind_ele.SETTING_DEVICE_UPGRADE)
                if u:
                    u.click()
                    break
                else:
                    continue
        except:
            pass

    # 门锁获取当前版本
    def lock_get_now_version(self):
        if self.find_element(app_bind_ele.LOCK_HIGH_VERSION_TEXT, timeout=3):
            return 0  # 旧版，需要升级
        if self.find_element(app_bind_ele.LOCK_LOW_VERSION_TEXT, timeout=3):
            return 1  # 最新版本了，无需升级
        if self.find_element(app_bind_ele.UPLOAD_TRY_AGAIN, timeout=3):
            print('?重试？？？？？')
            raise Exception('升级失败-"重试"')
        else:
            return -1  # 疑似异常或者正在升级中

    # 门锁
    def lock_ota_result(self):
        upgrade = self.find_element(app_bind_ele.UPGRADE_NOW, timeout=3)
        if upgrade:
            return 0  # 疑似升级完成
        again = self.find_element(app_bind_ele.UPLOAD_TRY_AGAIN, timeout=3)
        if again:
            return 1  # 升级失败

    def setting_btn_st(self):
        self.find_element_clickable(app_bind_ele.DOOR_LOCK_RIGHT_SETTING)

    # 生态门锁解绑
    def unbind_st(self):
        try:
            # 点击设备
            self.click_door_lock_window()
            # 右上角 设置
            self.setting_btn_st()
            self.find_element_clickable(app_bind_ele.DELETE_DEVICE, timeout=5)
            stime = time.time()
            while time.time() - stime < 10:
                try:
                    self.find_element_clickable(app_bind_ele.DELETE_AND_CLEAN, timeout=5)
                    self.find_element_clickable(app_bind_ele.DELETE_AND_CLEAN, timeout=5)
                except:
                    pass
        except:
            pass

    def unbind(self):
        # 解绑
        try:
            while True:
                self.in_home_page()
                item_setting = self.find_element(app_bind_ele.HOME_ITEM_SETTING, timeout=3)
                # 有设置按钮，优先点击设置， 没有设置，从云录页面进入设置页， 没有云录，从实时画面进卡录，再进设置，真鸡巴难啊
                if item_setting:
                    item_setting.click()
                else:
                    # 从云录页面进入设置页
                    cloud_btn = self.find_element(app_bind_ele.HOME_CLOUD_FLOW_BUTTON, timeout=5)
                    if cloud_btn:
                        cloud_btn.click()
                        print('click cloud')
                        setting_icon = self.find_element(app_bind_ele.CLOUD_SETTING)
                        if setting_icon:
                            setting_icon.click()
                        else:
                            continue
                    else:
                        # 没有云录，从实时画面进卡录，再进设置
                        live = self.find_element(app_bind_ele.START_PLAY, timeout=5)
                        if live:
                            live.click()
                            time.sleep(5)
                            record = self.find_element(app_bind_ele.CARD_PAGE_BUTTON, timeout=5)
                            if record:
                                record.click()
                                settings = self.find_element(app_bind_ele.HOME_ITEM_SETTING, timeout=3)
                                if settings:
                                    settings.click()
                        else:
                            break

                # print('???','点了云录设置按钮')
                time.sleep(10)
                self.swipe_by_screen(direction='up', scale=0.9)
                self.swipe_by_screen(direction='up', scale=0.9)
                self.swipe_by_screen(direction='up', scale=0.9)
                delete = self.find_element(app_bind_ele.DELETE_DEVICE, timeout=5)
                if delete:
                    delete.click()
                else:
                    continue
                stime = time.time()
                while time.time() - stime < 10:
                    try:
                        self.find_element_clickable(app_bind_ele.DELETE_AND_CLEAN, timeout=5)
                        self.find_element_clickable(app_bind_ele.DELETE_AND_CLEAN, timeout=5)
                    except:
                        pass
        except Exception as e:
            print('完成解绑')

    def lock_unbind(self):
        # 解绑
        try:
            while True:
                self.in_home_page()
                self.click_device_flow_window()
                setting = self.find_element(app_bind_ele.LOCK_SETTING, timeout=3)
                if setting:
                    setting.click()
                else:
                    break
                time.sleep(1)
                self.swipe_by_screen(direction='up', scale=0.9)
                self.swipe_by_screen(direction='up', scale=0.9)
                self.swipe_by_screen(direction='up', scale=0.9)
                delete = self.find_element(app_bind_ele.DELETE_DEVICE, timeout=5)
                if delete:
                    delete.click()
                else:
                    continue
                stime = time.time()
                while time.time() - stime < 10:
                    try:
                        self.find_element_clickable(app_bind_ele.DELETE_AND_CLEAN, timeout=5)
                        self.find_element_clickable(app_bind_ele.DELETE_AND_CLEAN, timeout=5)
                    except:
                        pass
        except Exception as e:
            print('完成解绑')

    def find_device(self, pk, click_item=None, fast_swipe=0):
        self.ignore()
        self.find_element_clickable(app_bind_ele.HOME_ADD_DEVICE, timeout=15)
        self.ignore()
        self.find_element_clickable(app_bind_ele.HOME_ADD_MENU_ADD)
        self.ignore()
        self.find_element_clickable(app_bind_ele.ADD_DEVICES_BY_CATEGORY)
        if click_item:
            # 点击摄像机分类 快速定位设备
            self.find_element_clickable(app_bind_ele.CAMERA_TYPE)
        if fast_swipe != 0:
            for _ in range(fast_swipe):
                self.swipe_by_screen(direction='up', scale=0.8)

        stime = time.time()
        while True:
            print('找设备')
            ipc = self.find_element(app_bind_ele.get_Aid_by_pk(pk), timeout=2)
            if ipc:
                ipc.click()
                print('找到了被测设备')
                time.sleep(1.5)
                break
            else:
                if time.time() - stime < 300:
                    self.swipe_by_screen(direction='up', scale=0.8)
                else:
                    raise Exception(f'300秒设备列表中没找到被测设备:{pk}')

    def bind_type(self, bind_type):
        try:
            # 有的设备 配网方式在引导页的右上角，需要点击才弹出
            self.find_element_clickable(app_bind_ele.CHANGE_BING_TYPE_BTN, timeout=3)
        except:
            pass
        # 0声波， 1AP，2蓝牙，3有线，4设备扫手机，54G
        if bind_type == '声波':
            # '声波配网'
            e = self.find_element(app_bind_ele.BIND_TYPE_SOUND)
            if e:
                e.click()
        elif bind_type == 'AP':
            # '通过WiFi进行配网'
            e = self.find_element(app_bind_ele.BIND_TYPE_WIFI)
            if e:
                e.click()
        elif bind_type == '蓝牙':
            # '蓝牙配网'
            e = self.find_element(app_bind_ele.BIND_TYPE_BLUE)
            if e:
                e.click()
        elif bind_type == '有线':
            # '有线配网'
            e = self.find_element(app_bind_ele.BIND_TYPE_LINE)
            if e:
                e.click()
        elif bind_type == '设备扫手机':
            # 设备扫手机二维码
            e = self.find_element(app_bind_ele.BIND_TYPE_QR)
            if e:
                e.click()
        elif bind_type == '4G':
            # '4G配网'
            e = self.find_element(app_bind_ele.BIND_TYPE_4G)
            if e:
                e.click()
        else:
            print('绑定方式不正确')

    # 设备扫手机二维码 临时
    def device_qr_phone(self):
        time.sleep(1)
        print('准备点击配网方式1')
        e = self.find_element(app_bind_ele.BIND_TYPE_WIFI2)
        if e:
            e.click()
            print('准备点击配网方式2')
            time.sleep(0.5)
        e = self.find_element(app_bind_ele.BIND_TYPE_QR)
        if e:
            e.click()
            print('准备点击配网方式3')

    def click_get_device_beep(self):
        self.find_element_clickable(app_bind_ele.GET_DEVICE_BEEP)
        print('已听到设备发出接收成功提示音')

    def guide_page(self):
        stime = time.time()
        while time.time() - stime < 40:
            try:
                cb = self.find_element(app_bind_ele.CHECKBOX_, timeout=1)
                if cb:
                    cb.click()
            except:
                pass
            try:
                time.sleep(0.5)
                e_info = self.find_element(app_bind_ele.NEXTBTN1, timeout=1).info
                if e_info['enabled']:
                    print('能点下一步了')
                    break
            except:
                pass

        # 下一步
        try:
            # print('下一步？？？？？')
            s_time = time.time()
            while time.time() - s_time < 40:
                # print('当前页面', self.get_current_app()['activity'])
                if 'com.q360.fastconnect.ui.FCH5Activity' == self.get_current_app()['activity']:
                    self.find_element_clickable(app_bind_ele.NEXTBTN1)
                    time.sleep(0.5)
                else:
                    break
        except Exception as e:
            print('???', e)
            pass

    def search_device(self):
        print('搜索设备')
        for _ in range(5):
            ipc = self.find_element(app_bind_ele.DEVICE_CONNECT_WIFI, timeout=45)
            if ipc:
                print('搜到设备')
                ipc.click()
                return True
            else:
                again = self.find_element(app_bind_ele.SEARCH_TRY_FIND, timeout=6)
                if again:
                    again.click()
                    print('没搜到，再搜一次')
        print('搜索5次，没搜到设备')

    def i_know(self):
        try:
            self.find_element_clickable(app_bind_ele.I_KNOW, timeout=2)
        except:
            pass
        try:
            self.find_element_clickable(app_bind_ele.NEAR, timeout=2)
        except:
            pass

    def input_ssid(self, wifi_name, wifi_pwd):
        # 不支持5G弹框
        self.i_know()
        self.input_text(ele=app_bind_ele.WIFI_NAME, text=wifi_name)
        self.input_text(ele=app_bind_ele.WIFI_PWD, text=wifi_pwd)
        self.just_back()
        time.sleep(0.5)
        self.find_element_clickable(app_bind_ele.NEXTBTN2)
        self.i_know()

    def send_sound(self):
        self.find_element_clickable(app_bind_ele.SOUND_CHECKBOX_BTN)
        self.find_element_clickable(app_bind_ele.SEND_SOUND_BTN)

    def conn_ap(self):
        stime = time.time()
        while time.time()-stime < 30:
            print('等 链接')
            e_list = self.find_elements(app_bind_ele.CONNECT_AP_BTN, timeout=2)
            for e in e_list:
                try:
                    if e.get_text() == '连接':
                        time.sleep(1)
                        e.click()
                        print('真点 连接')
                        return
                except Exception as e:
                    pass

    def conn_result(self, isAp=False):
        # if isAp:
        #     self.conn_ap()

        for index in range(30):
            print(f'查询结果 {index}')
            # Ap 重试逻辑 新加的
            if isAp:
                try:
                    e_list = self.find_elements(app_bind_ele.CONNECT_AP_BTN, timeout=2)
                    for e in e_list:
                        try:
                            if e.get_text() == '连接':
                                time.sleep(1)
                                e.click()
                                print('点 连接 AP')
                                break
                            if e.get_text() == '重试':
                                time.sleep(1)
                                e.click()
                                print('点 重试')
                                break
                            if e.get_text() == '确定':
                                time.sleep(1)
                                e.click()
                                print('点 确定')
                                break
                        except Exception as e:
                            pass
                except:
                    pass
            # Ap 重试逻辑 新加的

            success = self.find_element(app_bind_ele.BIND_SUCCESS, timeout=3)
            if success:
                success.click()
                time.sleep(1)
                return '绑定成功'
            fail = self.find_element(app_bind_ele.BIND_FAIL, timeout=3)
            if fail:
                raise Exception('真绑定失败')
            if index == 29:
                raise Exception('180秒没查出结果，直接算失败')

    def get_app_log(self):
        try:
            flutter_cmd = f'/sdcard/Android/data/{self.get_current_app()["package"]}/cache/log'
            gen = os.path.join(BASE_PATH, 'applog')
            if not os.path.exists(gen):
                os.mkdir(gen)
            flutter_path = f'{gen}/log_{time.strftime(time.strftime(YMDHMS__))}'
            os.popen(f'adb pull {flutter_cmd} {flutter_path}')
            print('获取app日志成功')
        except Exception as e:
            print('获取app日志失败')

    def get_app_log_sb(self):
        try:
            log_gen = f'/sdcard/Android/data/{self.get_current_app()["package"]}/cache'
            print('loggen', log_gen)
            gen = os.path.join(BASE_PATH, 'applog')
            if not os.path.exists(gen):
                os.mkdir(gen)
            local_path = f'{gen}/log_{time.strftime(time.strftime(YMDHMS__))}.tar.gz'

            device = adb.device()
            device.shell(f'cd {log_gen} ;cp -r log log_old')
            time.sleep(2)
            device.shell(f'cd {log_gen} ;chmod -R 777 /log_old')
            device.shell(f"cd {log_gen} ;tar -czvf log_old.tar.gz log_old")
            time.sleep(5)
            print('start pull', time.time())
            device.sync.pull(log_gen+'/log_old.tar.gz', local_path)
            time.sleep(5)
            print('pull done', time.time())
            # time.sleep(10)
            print('remove file', time.time())
            device.shell(f"cd {log_gen} ;rm -rf log_old.tar.gz")
            device.shell(f"cd {log_gen} ;rm -rf log_old")
            print('remove done', time.time())
            print('获取app日志成功')
        except Exception as e:
            print('获取app日志失败', e)


    def click_device_flow_window(self):
        """
        点击首页设备的开流窗口
        """
        # ww = self.find_element(app_bind_ele.DEVICE_FLOW_WINDOW, timeout=1)

        # 获取页面资源，提取card_ 用于定位卡片
        page_source = str(self.get_page_source())
        matches = re.findall(r'content-desc="(card_[^"]+)"', page_source)
        ww = self.find_element(app_bind_ele.get_home_item(matches[0]), timeout=1)

        if ww is not None:
            print('点击卡片', matches[0])
            ww.click()
            return True
        else:
            print("点击失败了")
        return False



    # 开流-兼容不同设备的实时画面入口
    def click_home_real_play(self):
        time.sleep(1)
        real_play = self.find_element(app_bind_ele.START_PLAY, timeout=2)
        if real_play:
            print('点击实时画面按钮')
            real_play.click()
        else:
            self.click_device_flow_window()

    # 点击实时画面开流
    def click_live(self):
        self.find_element_clickable(app_bind_ele.START_PLAY)

    # 校验开流成功
    def wait_real_page_flow_success(self, timeout=60):

        stime = time.time()
        if self.platform == GlobalVar.IOS:
            while time.time()-stime < timeout:
                flow_call_appear = self.find_element(app_bind_ele.CALL_BUTTON, timeout=0.20)
                if flow_call_appear is not None:
                    if self.get_ele_attribute(flow_call_appear, attribute_value='enabled'):
                        print("实时画面开流成功")
                        return True
                assert False, "实时画面开流失败"
        else:
            while time.time()-stime < timeout:
                flow_call_appear = self.find_element(app_bind_ele.CALL_BUTTON, timeout=0.20)
                if flow_call_appear is not None:
                    if self.get_ele_attribute(flow_call_appear, attribute_value="enabled"):
                        print("实时画面开流成功")
                        return True
            assert False, "实时画面开流失败"

    # 点击清晰度
    def click_clarity(self):
        stime = time.time()
        while time.time()-stime < 60:
            c_btn = self.find_element(app_bind_ele.QUALITY_BUTTON, timeout=2)
            if c_btn:
                c_btn.click()
                self.random_switch_clarity()
                break
            else:
                self.find_element_clickable(app_bind_ele.VIDEO_WIN, timeout=2)

        stime = time.time()
        while time.time()-stime < 60:
            c_btn_list = self.find_elements(app_bind_ele.QUALITY_BUTTON, timeout=2)
            if c_btn_list:
                if len(c_btn_list) == 2:
                    c_btn_list[1].click()
                    self.random_switch_clarity()
                break
            else:
                self.find_element_clickable(app_bind_ele.VIDEO_WIN, timeout=2)

    # 随机切换清晰度
    def random_switch_clarity(self):
        c_list = [app_bind_ele.SUPER3K_QUALITY, app_bind_ele.SUPER25K_QUALITY, app_bind_ele.SUPER_QUALITY,
                  app_bind_ele.HIGH_QUALITY, app_bind_ele.SMOOTH_QUALITY, app_bind_ele.STANDARD_QUALITY,
                  app_bind_ele.AUTO_QUALITY]
        stime = time.time()
        while time.time()-stime < 30:
            index = randint(0, len(c_list) - 1)
            btn = self.find_element(c_list[index], timeout=1)
            if btn:
                btn.click()
                break

    def click_home_myself(self):
        """
        点击首页我的
        """
        self.find_element_clickable(app_bind_ele.MYSELF)

    def click_just_setting_btn(self):
        """
        点击我的-设置按钮-
        """
        self.find_element_clickable(app_bind_ele.MYSELF_SETTING)
        self.sleep_op(1)

    # 关于App
    def click_about_app(self):
        self.swipe_by_screen(direction='up')
        self.find_element_clickable(app_bind_ele.MYSELF_ABOUT_APP)

    # 点击首页云录像
    def click_home_cloud(self):
        self.find_element_clickable(app_bind_ele.HOME_CLOUD_FLOW_BUTTON)

    def click_card_play(self):
        """
        点击tab页面的卡录像
        """
        self.find_element_clickable(app_bind_ele.CARD_PAGE_BUTTON)

    def wait_card_page_flow_success(self):
        stime = time.time()
        while time.time()-stime < 30:
            # //*[@content-desc="视频安全加载中..."]
            try:
                flow_call_appear = self.find_element(app_bind_ele.RECORD_PLAY_SUCCESS, timeout=0.20)
                if flow_call_appear is not None:
                    enabled_v = self.get_ele_attribute(flow_call_appear, attribute_value="enabled")
                    if enabled_v:
                        print("卡录开流成功")
                        return True
            except Exception as e:
                print(e)

        assert False, "卡录开流失败，超时（30秒）"


    def click_door_lock_window(self):
        """
        点击首页设备的开流窗口
        """
        # ww = self.find_element(app_bind_ele.DEVICE_FLOW_WINDOW)
        # x1, y1, x2, y2 = self.get_ele_attribute(ww, attribute_value='bounds')
        # x = x1 + (x2-x1)/2
        # y = y1 - 300
        # self.driver.click(x, y)
        self.click_device_flow_window()

    def click_real_flow_btn(self):
        """
        点击实时画面按钮
        """
        time.sleep(2)
        self.find_element_clickable(app_bind_ele.DOOR_LOCK_FLOW)

    def wait_door_lock_flow_success(self):
        """判断门锁实时画面开流"""
        # if self.element_bounds_exist('网络断开', timeout=3):
        #     assert False, "门锁已离线, 开流失败"
        # print("判断门锁开流")
        s_time = time.time()
        while time.time() - s_time <30:
            try:
                flow_call_appear = self.find_element(app_bind_ele.DOOR_LOCK_CALL, timeout=1)
                # self.click_screen_center()
                if flow_call_appear is None:
                    self.click_screen_center()
                    flow_call_appear = self.find_element(app_bind_ele.DOOR_LOCK_CALL, timeout=1)
                if self.get_ele_attribute(flow_call_appear, attribute_value='enabled') is True:
                    print("实时画面开流成功")
                    return True
            except Exception as e:
                print(e)
                self.click_screen_center()
                # print(time.time())
                continue
        assert False, "实时画面开流失败"

        # while time.time() - s_time <= 50:
        #     if self.judge_element_exists(app_bind_ele.DOOR_LOCK_CALL, timeout=0.5):
        #         self.tap_screen(0.5, 0.4)
        #         time.sleep(0.5)
        #         self.tap_screen(0.5, 0.4)
        #         flow_call_appear = self.find_element(app_bind_ele.DOOR_LOCK_CALL, timeout=1)
        #         if self.get_ele_attribute(flow_call_appear, attribute_value='enabled') is True:
        #             print("实时画面开流成功")
        #             return True
        #     else:
        #         self.tap_screen(0.5, 0.5)
        #         flow_call_appear = self.find_element(app_bind_ele.DOOR_LOCK_CALL, timeout=1)
        #         if self.get_ele_attribute(flow_call_appear, attribute_value='enabled') is True:
        #             print("实时画面开流成功")
        #             return True
        # print("实时画面开流超时")
        # # logAPP.download_action(screenshot=self.element_screenshot, describe="实时画面开流失败")
        # assert False, "实时画面开流失败"